<template>
  <a-modal
    title="启用"
    v-model="show"
    :maskClosable="false"
    :width="1050"
    placement="right"
    :closable="true"
    @cancel="onClose"
    :footer="null"
    :visiable="noTxnRegUseVisiable"
  >
    <a-form :form="form">
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="收单机构代码"
                       v-bind="formItemLayout">
            <a-input v-decorator="['acqInstCode']" :disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="收单机构名称"
                       v-bind="formItemLayout">
            <a-input v-decorator="['acqInstName']" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户编号"
                       v-bind="formItemLayout">
            <a-input v-decorator="['mchntNo']" :disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户名称"
                       v-bind="formItemLayout">
            <a-input v-decorator="['mchntName']" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户类型"
                       v-bind="formItemLayout">
            <a-select
              mode="default"
              :allowClear="true"
              style="width: 100%"
              show-search
              placeholder="请选择"
              option-filter-prop="children"
              :filter-option="filterOption"
              v-decorator="['mchntType',{rules: [{ required: true, message: '必填' }]}]">
              <a-select-option key="00">普通商户</a-select-option>
              <a-select-option key="10">连锁商户</a-select-option>
              <a-select-option key="11">连锁商户门店</a-select-option>
              <a-select-option key="20">小微商户</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户联系方式"
                       v-bind="formItemLayout">
            <a-input v-decorator="['mchntContactPhone']" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="终端二维码标识"
                       v-bind="formItemLayout">
            <a-input v-decorator="['termNo']" :disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="最终交易时间"
                       v-bind="formItemLayout">
            <a-input v-decorator="['endTxnTime']" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="微信昵称"
                       v-bind="formItemLayout">
            <a-input v-decorator="['wechatName']" :disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>

      <br>

    </a-form>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="onClose" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button>
    </div>
  </a-modal>
</template>
<script>
  const formItemLayout = {
    labelCol: {span: 8},
    wrapperCol: {span: 16}
  }
  export default {
    name: 'NoTxnRegUse',
    props: {
      noTxnRegUseVisiable: {
        default: false
      },
      instId: '',
    },
    data() {
      return {
        loading: false,
        formItemLayout,
        form: this.$form.createForm(this),
        validateStatus: '',
        // firstValue: {},
        info: {
          infoName: '',
          remark: '',
          menuId: ''
        }
      }
    },
    computed: {
      show: {
        get: function () {
          return this.noTxnRegUseVisiable
        },
        set: function () {
        }
      }
    },
    mounted() {

    },

    methods: {
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },

      reset() {
        this.loading = false
        this.form.resetFields()
      },
      onClose() {
        this.reset()
        this.$emit('close')
      },
      handleSubmit() {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.setInfoFields()
            this.loading = true
            this.info.instId = this.instId

            this.info.optFlag = 'use'
            console.log(this.info)
            this.$put('/admin/csmc/noTxnReg', {
              ...this.info
            }).then((r) => {
              this.reset()
              this.$emit('success')
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },

      setInfoFields() {
        let values = this.form.getFieldsValue(['acqInstCode', 'acqInstName', 'mchntNo', 'mchntName',
          'mchntType', 'mchntContactPhone', 'termNo', 'endTxnTime', 'wechatName'])
        if (typeof values !== 'undefined') {
          Object.keys(values).forEach(_key => {
            this.info[_key] = values[_key]
          })
        }
      },

      setNoTxnRegFormValues ({...info}) {
        let fields = ['acqInstCode', 'acqInstName', 'mchntNo', 'mchntName', 'mchntType',
          'mchntContactPhone', 'termNo', 'endTxnTime', 'wechatName']

        Object.keys(info).forEach((key) => {
          if (fields.indexOf(key) !== -1) {
            this.form.getFieldDecorator(key)
            let obj = {}
            obj[key] = info[key]
            this.form.setFieldsValue(obj)
          }
        })
      },

    }

  }
</script>


